package de.unifa.elostplugin.gui.wizards.pages;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.custom.CLabel;

import de.unifa.elostplugin.gui.wizards.beans.BuildBeanDecision;
import de.unifa.elostplugin.gui.wizards.*;


import org.eclipse.core.databinding.DataBindingContext;
import org.eclipse.core.databinding.observable.value.IObservableValue;
import org.eclipse.jface.databinding.swt.WidgetProperties;
import org.eclipse.core.databinding.beans.PojoProperties;


public class BuildPageDecision extends WizardPage {
	@SuppressWarnings("unused")
	private DataBindingContext m_bindingContext;



	private Button rdbLocalNoRelease;
	private BuildBeanDecision decision;
	private Button rdbBranchRelease;
	private Button rdbTrunkRelease;
	private Button rdbTrunkMainRelease;
	private Button rdbTrunktag2branch;
	/**
	 * @return the decision
	 */
	public BuildBeanDecision getDecision() {
		return decision;
	}

	/**
	 * @param decision the decision to set
	 */
	public void setDecision(BuildBeanDecision decision) {
		this.decision = decision;
	}

	/**
	 * Create the wizard.
	 */
	public BuildPageDecision() {
		super("wizardPage");
		setTitle("Bauassistent");
		setDescription("W\u00E4hlen sie die Art zu Bauen aus.");
		decision = ((BuildWizard)getWizard()).getDecision();
	}

	/**
	 * Create contents of the wizard.
	 * @param parent
	 */
	public void createControl(Composite parent) {
		Composite container = new Composite(parent, SWT.NULL);

		setControl(container);
		RowLayout rl_container = new RowLayout(SWT.VERTICAL);
		rl_container.marginTop = 10;
		rl_container.marginLeft = 50;
		container.setLayout(rl_container);
		
		rdbLocalNoRelease = new Button(container, SWT.RADIO);
		rdbLocalNoRelease.setText("local_norelease");
		
		CLabel lblLocalNoRelease = new CLabel(container, SWT.NONE);
		lblLocalNoRelease.setLeftMargin(16);
		lblLocalNoRelease.setBottomMargin(10);
		lblLocalNoRelease.setText("Erzeugt eine JAR-File aus dem lokalen Source-Stand des Entwickler-PCs. \r\nEs wird kein Release-Tag im svn generiert.");
		
		rdbBranchRelease = new Button(container, SWT.RADIO);
		rdbBranchRelease.setText("branch_release");
		
		CLabel lblBranchRelease = new CLabel(container, SWT.NONE);
		lblBranchRelease.setTopMargin(0);
		lblBranchRelease.setText("Erzeugt eine Jar-File aus dem angegebenen Branch und generiert ein neues Release Tag");
		lblBranchRelease.setLeftMargin(16);
		lblBranchRelease.setBottomMargin(10);
		
		rdbTrunkRelease = new Button(container, SWT.RADIO);
		rdbTrunkRelease.setText("trunk_release");
		
		CLabel lblTrunkRelease = new CLabel(container, SWT.NONE);
		lblTrunkRelease.setTopMargin(0);
		lblTrunkRelease.setText("Erzeugt eine JAR-File aus dem Trunk und erstellt einen neuen Release-Tags im SVN.");
		lblTrunkRelease.setLeftMargin(16);
		lblTrunkRelease.setBottomMargin(10);
		
		
		rdbTrunkMainRelease = new Button(container, SWT.RADIO);
		rdbTrunkMainRelease.setText("trunk_mainrelease");
		
		CLabel lblTrunkMainRelease = new CLabel(container, SWT.NONE);
		lblTrunkMainRelease.setTopMargin(0);
		lblTrunkMainRelease.setText("Erzeugt eine JAR-File aus dem Trunk und generiert ein neues Haupt-Release-Tag im svn. ");
		lblTrunkMainRelease.setLeftMargin(16);
		lblTrunkMainRelease.setBottomMargin(10);
		
		rdbTrunktag2branch = new Button(container, SWT.RADIO);
		rdbTrunktag2branch.setText("trunktag2branch");
		
		CLabel lblTrunktag2Branch = new CLabel(container, SWT.NONE);
		lblTrunktag2Branch.setTopMargin(0);
		lblTrunktag2Branch.setText("Erzeugen eines neuen Branches aus einem aus dem Trunk generierten Tag.");
		lblTrunktag2Branch.setLeftMargin(16);
		lblTrunktag2Branch.setBottomMargin(10);
		m_bindingContext = initDataBindings();
	
	}
	protected DataBindingContext initDataBindings() {
		DataBindingContext bindingContext = new DataBindingContext();
		//
		IObservableValue observeSelectionRdbLocalNoReleaseObserveWidget = WidgetProperties.selection().observe(rdbLocalNoRelease);
		IObservableValue localNoReleaseDecisionObserveValue = PojoProperties.value("localNoRelease").observe(decision);
		bindingContext.bindValue(observeSelectionRdbLocalNoReleaseObserveWidget, localNoReleaseDecisionObserveValue, null, null);
		//
		IObservableValue observeSelectionRdbBranchReleaseObserveWidget = WidgetProperties.selection().observe(rdbBranchRelease);
		IObservableValue branchReleaseDecisionObserveValue = PojoProperties.value("branchRelease").observe(decision);
		bindingContext.bindValue(observeSelectionRdbBranchReleaseObserveWidget, branchReleaseDecisionObserveValue, null, null);
		//
		IObservableValue observeSelectionRdbTrunkReleaseObserveWidget = WidgetProperties.selection().observe(rdbTrunkRelease);
		IObservableValue trunkReleaseDecisionObserveValue = PojoProperties.value("trunkRelease").observe(decision);
		bindingContext.bindValue(observeSelectionRdbTrunkReleaseObserveWidget, trunkReleaseDecisionObserveValue, null, null);
		//
		IObservableValue observeSelectionRdbTrunkMainReleaseObserveWidget = WidgetProperties.selection().observe(rdbTrunkMainRelease);
		IObservableValue trunkMainReleaseDecisionObserveValue = PojoProperties.value("trunkMainRelease").observe(decision);
		bindingContext.bindValue(observeSelectionRdbTrunkMainReleaseObserveWidget, trunkMainReleaseDecisionObserveValue, null, null);
		//
		IObservableValue observeSelectionRdbTrunktag2branchObserveWidget = WidgetProperties.selection().observe(rdbTrunktag2branch);
		IObservableValue trunktag2BranchDecisionObserveValue = PojoProperties.value("trunktag2Branch").observe(decision);
		bindingContext.bindValue(observeSelectionRdbTrunktag2branchObserveWidget, trunktag2BranchDecisionObserveValue, null, null);
		//
		return bindingContext;
	}
}
